package src;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author administrador
 */
public class Degub
{
    private static JTextArea debug;
    private static Degub de;
    private static WriteProprierts w;

    public synchronized static Degub getInstance()
    {
        if ( de == null )
        {
            de = new Degub();
            
        }

        if ( debug == null )
        {
            debug = new JTextArea();
            w = new WriteProprierts();
        }

        return de;
    }


    public void Debug( Exception mgn )
    {

        //System.out.println( "\n " + mgn );
        Debug( "EXCEPTION: " + mgn.getMessage() );
        w.write( WriteProprierts.ERRORS, mgn.getMessage() );
    }

    public void Debug( String mgn )
    {
       //System.out.println( "\n " + mgn );
        debug.append( "\n " + mgn );

        w.write( WriteProprierts.DEBUG, debug.getText() );

    }

    public void DebugSameLine( String mgn )
    {
        //System.out.println( mgn );
        debug.append( mgn );

        w.write( WriteProprierts.DEBUG, debug.getText() );
    }


    public void debugShow()
    {
        JFrame debugFrame = null;
        JScrollPane scroll = new JScrollPane();

        if ( debugFrame == null )
        {
            debugFrame = new JFrame();
            scroll.setViewportView( debug );
            scroll.setAutoscrolls( true );
            debug.setLineWrap( true );
            debugFrame.add( scroll );
            debugFrame.setSize( 500, 500 );
            debugFrame.show();
        }
    }
}
